From 6e9e50d87c8869882de920c096125af36218ae06 Mon Sep 17 00:00:00 2001 From: Eric Curtin Date: Tue, 22 Aug 2023 13:11:30 +0100 Subject: [PATCH] prepare-root: Changes made to find_proc_cmdline_key Used strspn based on feedback from similar function. --- src/switchroot/ostree-mount-util.h | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/switchroot/ostree-mount-util.h b/src/switchroot/ostree-mount-util.h index 1c15fe90..eb79efdf 100644 --- a/src/switchroot/ostree-mount-util.h +++ b/src/switchroot/ostree-mount-util.h @@ -87,29 +87,26 @@ cleanup_free (void *p) static inline char * find_proc_cmdline_key (const char *cmdline, const char *key) { - char *ret = NULL; - size_t key_len = strlen (key); - - const char *iter = cmdline; - while (iter != NULL) + const size_t key_len = strlen (key); + for (const char *iter = cmdline; iter;) { const char *next = strchr (iter, ' '); - const char *next_nonspc = next; - while (next_nonspc && *next_nonspc == ' ') - next_nonspc += 1; if (strncmp (iter, key, key_len) == 0 && iter[key_len] == '=') { const char *start = iter + key_len + 1; if (next) - ret = strndup (start, next - start); - else - ret = strdup (start); - break; + return strndup (start, next - start); + + return strdup (start); } - iter = next_nonspc; + + if (next) + next += strspn (next, " "); + + iter = next; } - return ret; + return NULL; } /* This is an API for other projects to determine whether or not the -- 2.30.2